﻿using System;
using System.Text.RegularExpressions;

namespace TheCollectiveNetwork.Classes.GlobalFunctions
{
    
    public class strfunc {
        public static string Left(string text, int length)
        {
            string rtnstring;

            if (length <= 0 || text.Length == 0) { 
                rtnstring = string.Empty; }
            else if (text.Length <= length) { 
                rtnstring = text; }
            else { 
                rtnstring = text.Substring(0, length); }

            return rtnstring;
        }

        public static bool ValidateGUID(string p_guid_str)
        {
            /*Returns true if guid is valid otherwise returns false*/
            Regex isguid;

            /*Setup regular expression foramt*/
            isguid = new Regex("^(\\{){0,1}[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{4}\\-[0-9a-fA-F]{12}(\\}){0,1}$", RegexOptions.Compiled);
            if (string.IsNullOrEmpty(p_guid_str) == false)
            {
                if (isguid.IsMatch(p_guid_str)) { return true; }
                else { return false; }
            }
            else
            { return false; }
        }

        // This function strips out potentially unwanted characters in a string
        public static string FilteredString(string pRawString)
        {            
            return Regex.Replace(pRawString, "[^0-9a-z'\"~@_\\-\\.]", string.Empty, RegexOptions.IgnoreCase);
        }
       
    }

        
}
